package com.hongmeng.web.controller.operater;

import java.util.List;

import com.hongmeng.common.constant.Constants;
import com.hongmeng.operater.domain.AddLeaveMessage;
import com.hongmeng.operater.domain.newsAndVideo.entity.NewsInfoEntity;
import com.hongmeng.operater.domain.newsAndVideo.entity.QueryVideoInfoEntity;
import com.hongmeng.operater.domain.newsAndVideo.entity.VideoDetailListEntity;
import com.hongmeng.operater.service.IHmLeaveMessageService;
import com.hongmeng.operater.service.moduleResource.IHmModuleResourceService;
import com.hongmeng.operater.service.newsAndVideo.IHmVideoService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hongmeng.common.core.controller.BaseController;
import com.hongmeng.common.core.domain.AjaxResult;
import com.hongmeng.operater.domain.newsAndVideo.HmNews;
import com.hongmeng.operater.service.newsAndVideo.IHmNewsService;
import com.hongmeng.common.core.page.TableDataInfo;
/**
 * 个人请求（不需要验证权限）
 * @author hongmeng
 * @date 2020-12-28
 */
@Api("非权限验证接口")
@RestController
@RequestMapping("/person")
public class PersonController extends BaseController{

    @Autowired
    private IHmNewsService hmNewsService;

    @Autowired
    private IHmVideoService hmVideoService;

    @Autowired
    private IHmModuleResourceService hmModuleResourceService;

    @Autowired
    private IHmLeaveMessageService hmLeaveMessageService;

    /**
     * 查询文章信息列表
     */
    @ApiOperation("查询文章信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "标题", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keyWord", value = "关键字", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "belongToSpecialty", value = "所属专科", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "newsState", value = "状态", dataType = "String", paramType = "query")
    })
    @GetMapping("/news/list")
    public TableDataInfo list(String title,String keyWord,String belongToSpecialty,String newsState) {
        HmNews hmNews = new HmNews();
        hmNews.setTitle(title);
        hmNews.setKeyWord(keyWord);
        hmNews.setBelongToSpecialty(belongToSpecialty);
        //只查询审核通过的文章
        hmNews.setNewsState(Constants.NEWS_AND_VIDEO_STATE.PASS_AND_RELEASE);
        startPage();
        List<NewsInfoEntity> list = hmNewsService.selectHmNewsList(hmNews);
        return getDataTable(list);
    }

    /**
     * 获取文章信息详细信息(新增一个阅读量/浏览量)
     */
    @ApiOperation("获取文章信息详细信息新增一个阅读量/浏览量)")
    @ApiImplicitParam(name = "id", value = "文章ID", required = true, dataType = "int", paramType = "path")
    @GetMapping(value = "/news/getNewsInfo/{id}")
    public AjaxResult getNewsInfo(@PathVariable("id") Integer id) {
        return hmNewsService.getNewsInfo(id);
    }

    /**
     * 查询视频信息列表
     */
    @ApiOperation("查询视频信息列表")
    @GetMapping("/video/list")
    public TableDataInfo list(QueryVideoInfoEntity hmVideo)
    {
        //只查询审核通过的视频
        hmVideo.setVideoState(Constants.NEWS_AND_VIDEO_STATE.PASS_AND_RELEASE);
        startPage();
        List<VideoDetailListEntity> list = hmVideoService.selectVideoDetailList(hmVideo);
        return getDataTable(list);
    }

    /**
     * 获取视频信息详情
     */
    @ApiOperation("获取视频信息详情")
    @GetMapping(value = "/video/getDetailedInfo/{id}")
    public AjaxResult getDetailedInfo(@PathVariable("id") Integer id) {
        return hmVideoService.selectHmVideoDetailedById(id);
    }

    /**
     * 获取上一篇文章
     */
    @ApiOperation("获取上一篇文章")
    @GetMapping("/news/getPreviousNews")
    public AjaxResult getPreviousNews(Integer id){
        return hmNewsService.getAdjacentNews(id,Constants.GET_NEWS_TYPE.UP);
    }

    /**
     * 获取下一篇文章
     */
    @ApiOperation("获取下一篇文章")
    @GetMapping("/news/getNextNews")
    public AjaxResult getNextNews(Integer id){
        return hmNewsService.getAdjacentNews(id,Constants.GET_NEWS_TYPE.NEXT);
    }

    /**
     * 获取模块资源列表
     */
    @ApiOperation("获取模块资源列表")
    @GetMapping("/moduleResource/getModuleResourceList")
    public AjaxResult getModuleResourceList(){
        return hmModuleResourceService.queryModuleResourceList();
    }

    /**
     * 新增留言
     */
    @ApiOperation("新增留言")
    @PostMapping("/leaveMessage/addLeaveMessage")
    public AjaxResult addLeaveMessage(@RequestBody AddLeaveMessage addLeaveMessage) {
        return this.toAjax(this.hmLeaveMessageService.insertHmLeaveMessage(addLeaveMessage));
    }
}
